package com.design.pattern.state;

public class SoldState implements State {

    GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    public void insertQuarter() {
        System.out.println("你已经投了钱了，别投钱了");
    }

    public void ejectQuarter() {
        System.out.println("已经摇动摇杆了，正在出货呢，退不了钱了");
    }

    public void turnCrank() {
        System.out.println("已经摇动摇杆了，别再摇动了");
    }

    public void dispense() {
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("糖果已经卖完了，下次早点来");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}